/*******************************************************************************
 * Copyright (c) 2010 liw.
 * All rights reserved. 
 * 
 * This file is part of VanBus.
 * 
 *     VanBus is free software: you can redistribute it and/or modify
 *     it under the terms of the GNU General Public License as published by
 *     the Free Software Foundation, either version 3 of the License, or
 *     (at your option) any later version.
 * 
 *     VanBus is distributed in the hope that it will be useful,
 *     but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
 * 
 *     You should have received a copy of the GNU General Public License
 *     along with VanBus.  If not, see <http://www.gnu.org/licenses/>.
 * Contributors:
 *     liw - initial API and implementation
 ******************************************************************************/
package org.niclab.vanbus.model;

import java.util.HashMap;
import java.util.Map.Entry;

import org.niclab.vanbus.activity.controller.BusStopController;


import android.content.Context;
import android.os.Bundle;
import android.util.Log;

public class EndStopReminder extends Reminder{

	public static final String LOG_TAG="EndStopReminderModel";
		
	private BusStop prevStop;
	private BusStop nextStop;

	private long distanceToDest =-1;
	private long distancePrevToDest =-1;
	
	public EndStopReminder(BusRoute route, BusStop prevStop, BusStop destStop, BusStop nextStop){
		super(ReminderType.EndStopReminder,route, destStop);
		this.prevStop = prevStop;
		this.nextStop = nextStop;
		
	}
	
	
	
	public void setStops(BusStop prevStop, BusStop destStop, BusStop nextStop){
		this.prevStop = prevStop;
		this.stop = destStop;
		this.nextStop = nextStop;
		
	}
	
	
	
	public BusStop getPrevStop() {
		return prevStop;
	}

	public void setPrevStop(BusStop prevStop) {
		this.prevStop = prevStop;
	}

	public BusStop getDestStop() {
		return stop;
	}

	public void setDestStop(BusStop destStop) {
		this.stop = destStop;
	}

	public BusStop getNextStop() {
		return nextStop;
	}

	public void setNextStop(BusStop nextStop) {
		this.nextStop = nextStop;
	}

	
	public long getDistanceToDest() {
		return distanceToDest;
	}

	public void setDistanceToDest(long l) {
		this.distanceToDest = l;
	}

	public long getDistancePrevToDest() {
		return distancePrevToDest;
	}

	public void setDistancePrevToDest(long l) {
		this.distancePrevToDest = l;
	}
	
	public Bundle createBundle(){
		
		Bundle modelBundle = super.createBundle();
		
		Bundle prevStopBundle = new Bundle();
		prevStopBundle.putString("stopId", prevStop.getStopId());
		prevStopBundle.putDouble("lat", prevStop.getLatitude());
		prevStopBundle.putDouble("lng", prevStop.getLongitude());
		
		Bundle destStopBundle = new Bundle();
		destStopBundle.putString("stopId", stop.getStopId());
		destStopBundle.putDouble("lat", stop.getLatitude());
		destStopBundle.putDouble("lng", stop.getLongitude());
		
		Bundle nextStopBundle = new Bundle();
		nextStopBundle.putString("stopId", nextStop.getStopId());
		nextStopBundle.putDouble("lat", nextStop.getLatitude());
		nextStopBundle.putDouble("lng", nextStop.getLongitude());
		
		modelBundle.putBundle("prevStop",prevStopBundle);
		modelBundle.putBundle("destStop",destStopBundle);
		modelBundle.putBundle("nextStop",nextStopBundle);
		
		modelBundle.putLong("distanceToDest", this.distanceToDest);
		modelBundle.putLong("distancePrevToDest", this.distancePrevToDest);
		
		return modelBundle;
		
	}

	
	public EndStopReminder(Bundle bundle,Context context){
		super(bundle,context);
		BusStopController stopCtrl = new BusStopController();
		
		Bundle stopBundle = bundle.getBundle("prevStop");
		BusStop stop = stopCtrl.createBusStopFromCache(stopBundle.getString("stopId"));
		if(stop == null){
			stop = new BusStop();
			stop.setStopId(stopBundle.getString("stopId"));
			stop.setLatitude(stopBundle.getDouble("lat"));
			stop.setLongitude(stopBundle.getDouble("lng"));
		}
		
		this.prevStop = stop;
		
		stopBundle = bundle.getBundle("destStop");
		stop = stopCtrl.createBusStopFromCache(stopBundle.getString("stopId"));
		if(stop == null){
			stop = new BusStop();
			stop.setStopId(stopBundle.getString("stopId"));
			stop.setLatitude(stopBundle.getDouble("lat"));
			stop.setLongitude(stopBundle.getDouble("lng"));
		}
		
		this.stop = stop;
		
		stopBundle = bundle.getBundle("nextStop");
		stop = stopCtrl.createBusStopFromCache(stopBundle.getString("stopId"));
		if(stop == null){
			stop = new BusStop();
			stop.setStopId(stopBundle.getString("stopId"));
			stop.setLatitude(stopBundle.getDouble("lat"));
			stop.setLongitude(stopBundle.getDouble("lng"));
		}
		
		this.nextStop = stop;
		
		
		this.distanceToDest = bundle.getLong("distanceToDest");
		this.distancePrevToDest = bundle.getLong("distancePrevToDest");
		
	}
	

	

}
